package com.baibei.module.stock.simple;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.baibei.module.stock.basic.BasicKLineFragment;
import com.baibei.module.stock.basic.BasicNewKLineFragment;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;

/**
 * K线图
 * Created by ChenRui on 2017/4/17 0017 11:02.
 */
public class SimpleKLineFragment extends BasicNewKLineFragment {

    /**
     * @param type 参考{@link com.baibei.ebec.sdk.IQuotationApi#TYPE_KLINE_5} TYPE_*字段
     */
    public static SimpleKLineFragment newInstance(String type, int position, String productInfo) {
        Bundle args = new Bundle();
        args.putString("type", type);
        args.putInt("position", position);
        args.putString("productInfo", productInfo);
        SimpleKLineFragment fragment = new SimpleKLineFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // 选择
//        mKLineChart.addOnChartValueSelectedListener(new OnChartValueSelectedListener() {
//            @Override
//            public void onValueSelected(Entry e, Highlight h) {
//
//                SimpleStockFragment fragment = (SimpleStockFragment) getParentFragment();
//                int index = (int) e.getX();
//
//                CandleEntry entry = mKLineChart.getCandleData().getDataSetByIndex(0).getEntryForIndex(index);
//
//
//                CandleEntry perEntry = null;
//                float perclose = 0; // 昨收价
//
//                if (index - 1 >= 0) {
//                    perEntry = mKLineChart.getCandleData().getDataSetByIndex(0).getEntryForIndex(index - 1);
//                    perclose = perEntry.getClose();
//                }
//
//                String time = mKLineChart.getXAxisLabel(e.getX());
//
//                fragment.refreshKLineMarkView(
//                        perclose,
//                        time,
//                        entry.getHigh(),
//                        entry.getLow(),
//                        entry.getOpen(),
//                        entry.getClose());
//            }
//
//            @Override
//            public void onNothingSelected() {
//                SimpleStockFragment fragment = (SimpleStockFragment) getParentFragment();
//                fragment.dismissKLineMarkView();
//            }
//        });
    }
}
